home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / pctv3n2.zip / TVOUTERR.CPP < prev    next >
Text File  |  1992-02-13  |  3KB  |  126 lines

  1. #include <iostream.h>
  2.  
  3. #define Uses_otstream
  4. #define Uses_TApplication
  5. #define Uses_TDeskTop
  6. #define Uses_TRect
  7. #define Uses_TTerminal
  8. #define Uses_TWindow
  9. #include <tv.h>
  10.  
  11. class TOutputWindow : public TWindow
  12.   {
  13.   TTerminal *_term;
  14.  
  15.   public:
  16.  
  17.   TOutputWindow(TRect bounds, const char *title,
  18.   ostream_withassign& ostr, ushort bufsize);
  19.  
  20.   void attach(ostream_withassign& ostr)
  21.   {
  22.   // Attach TTerminal stream buffer to I/O stream.
  23.   ostr = _term;
  24.   }
  25.   };
  26.  
  27. class TOutErr : public TApplication
  28.   {
  29.   ostream_withassign _old_cout;
  30.   ostream_withassign _old_cerr;
  31.   ostream_withassign _old_clog;
  32.  
  33.   public:
  34.  
  35.   TOutErr(TRect& outbounds, ushort outbufsize, TRect& errbounds,
  36.   ushort errbufsize);
  37.  
  38.   ~TOutErr();
  39.  
  40.   virtual void run();
  41.   };
  42.  
  43. TOutputWindow::TOutputWindow(TRect bounds, const char *title,
  44. ostream_withassign& ostr, ushort bufsize) :
  45. TWindowInit(&TOutputWindow::initFrame),
  46. TWindow(bounds, title, wnNoNumber)
  47. {
  48. // Terminal view should cover entire window.
  49. bounds = getExtent();
  50. bounds.grow(-1, -1);
  51.  
  52. // Create terminal view and add to window.
  53. _term = new TTerminal(bounds,
  54. standardScrollBar(sbHorizontal | sbHandleKeyboard),
  55. standardScrollBar(sbVertical | sbHandleKeyboard), bufsize);
  56. insert(_term);
  57.  
  58. // Create TV output stream.
  59. otstream ot(_term);
  60.  
  61. ot << "Terminal window \"" << title << "\" created." << endl;
  62.  
  63. // Copy output stream; normally attach(ostr) would be sufficient.
  64. ostr = ot;
  65. }
  66.  
  67. TOutErr::TOutErr(TRect& outbounds, ushort outbufsize,
  68. TRect& errbounds, ushort errbufsize) :
  69. TProgInit(&TOutErr::initStatusLine, &TOutErr::initMenuBar,
  70. &TOutErr::initDeskTop)
  71. {
  72. // Save current I/O assignments.
  73. _old_cout = cout;
  74. _old_cerr = cerr;
  75. _old_clog = clog;
  76.  
  77. TOutputWindow *tow;
  78.  
  79. // Create standard output window.
  80. tow = new TOutputWindow(outbounds, "Standard Output", cout,
  81. outbufsize);
  82. deskTop->insert(tow);
  83.  
  84. // Create standard error window and attach to log stream.
  85. tow = new TOutputWindow(errbounds, "Standard Error", cerr,
  86. errbufsize);
  87. tow->attach(clog);
  88. deskTop->insert(tow);
  89. }
  90.  
  91. TOutErr::~TOutErr()
  92. {
  93. // Restore old I/O assignments.
  94. cout = _old_cout;
  95. cerr = _old_cerr;
  96. clog = _old_clog;
  97. }
  98.  
  99. void TOutErr::run()
  100. {
  101. cout << "Testing standard output:";
  102. for (int i = 0; i < 10; i++)
  103.   cout << ' ' << i;
  104. cout << endl;
  105.  
  106. cerr << "Testing standard error:";
  107. for (; i < 20; i++)
  108.   cerr << ' ' << i;
  109. cerr << endl;
  110.  
  111. clog << "Testing log:";
  112. for (; i < 30; i++)
  113.   clog << ' ' << i;
  114. clog << endl;
  115.  
  116. TApplication::run();
  117. }
  118.  
  119. int main()
  120. {
  121. TOutErr outerr(TRect(0, 0, 80, 15), 8192, TRect(0, 15, 80, 23),
  122. 2048);
  123. outerr.run();
  124. return (0);
  125. }
  126.